import { GUIComponent } from "../../../../../com/mui/controls/GUIComponent";
import { ScaleBitmap } from "../../../../../com/mui/display/ScaleBitmap";
import { ResouceConst } from "../../../../component/gconst/ResouceConst";
import { List } from "../../../../../fl/controls/List";
import { ListMenuCellRenderer } from "./ListMenuCellRenderer";
import { ListEvent } from "../../../../../fl/events/ListEvent";
import { DataProvider } from "../../../../../fl/data/DataProvider";
//class ListMenu
    
    export  class ListMenu extends GUIComponent
    {
        constructor(arg1: ScaleBitmap=null)
        {
            super();
            setSize(86, 121);
            this._bg = this.addChild(arg1 == null ? ResouceConst.getScaleBitmap("ToolTipBg") : arg1) as ScaleBitmap;
            this._list = new List();
            this._list.x = -4;
            this._list.y = 10;
            this._list.rowHeight = 18;
            this._list.horizontalScrollPolicy = "off";
            this._list.verticalScrollPolicy = "off";
            this._list.setStyle("skin", new Object /* flash.display.Bitmap */());
            this._list.setStyle("cellRenderer", ListMenuCellRenderer);
            this._list.addEventListener(ListEvent.ITEM_CLICK, this.itemClickHandler);
            this.addChild(this._list);
            return;
        }

        public get dataProvider(): DataProvider
        {
            return this._dataProvider;
        }

        public set dataProvider(arg1: DataProvider)
        {
            this._dataProvider = arg1;
            this._list.dataProvider = arg1;
            this._list.height = arg1.length * this._list.rowHeight;
            this.height = this._list.height + 21;
            return;
        }

        public set target(arg1: Object /* flash.display.DisplayObject */)
        {
            this._target = arg1;
            return;
        }

        public get target(): Object /* flash.display.DisplayObject */
        {
            return this._target;
        }

        public hide(): void
        {
            this.visible = false;
            if (this.hasEventListener(flash.events.Event.ENTER_FRAME)) 
            {
                this.removeEventListener(flash.events.Event.ENTER_FRAME, this.enterFrameHandler);
            }
            this._list.clearSelection();
            return;
        }

        public show(arg1: number, arg2: number, arg3: Object /* flash.display.DisplayObject */): void
        {
            this.x = arg1;
            this.y = arg2;
            this.target = arg3;
            if (!hasEventListener(flash.events.MouseEvent.MOUSE_OVER)) 
            {
                this.addEventListener(flash.events.MouseEvent.MOUSE_OVER, this.mouseOverHandler);
            }
            if (this._delayTimer) 
            {
                this._delayTimer.reset();
                this._delayTimer.start();
            }
            else 
            {
                this._delayTimer = new Object /* flash.utils.Timer */(3000);
                this._delayTimer.addEventListener(flash.events.TimerEvent.TIMER, this.delayTimerHandler);
                this._delayTimer.start();
            }
            this.visible = true;
            return;
        }

        /* internal  */enterFrameHandler(arg1: Object /* flash.events.Event */): void
        {
            if (!this._bg.hitTestPoint(stage.mouseX, stage.mouseY, true)) 
            {
                this.hide();
            }
            return;
        }

        /* internal  */mouseOverHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._delayTimer.stop();
            this._delayTimer.removeEventListener(flash.events.TimerEvent.TIMER, this.delayTimerHandler);
            this._delayTimer = null;
            this.removeEventListener(flash.events.MouseEvent.MOUSE_OVER, this.mouseOverHandler);
            this.addEventListener(flash.events.Event.ENTER_FRAME, this.enterFrameHandler);
            return;
        }

        /* internal  */delayTimerHandler(arg1: Object /* flash.events.TimerEvent */): void
        {
            this._delayTimer.stop();
            this._delayTimer.removeEventListener(flash.events.TimerEvent.TIMER, this.delayTimerHandler);
            this._delayTimer = null;
            this.hide();
            return;
        }

        /* internal  */itemClickHandler(arg1: ListEvent): void
        {
            var loc1=arg1.item;
            switch (loc1) 
            {
                case "":
                {
                    break;
                }
            }
            this.hide();
            return;
        }

        public get list(): List
        {
            return this._list;
        }

        public /* override */ set width(arg1: number)
        {
            super.width = arg1;
            this._bg.width = arg1;
            return;
        }

        public /* override */ set height(arg1: number)
        {
            super.height = arg1;
            this._bg.height = arg1;
            return;
        }

        /* internal */ /* var */_bg: ScaleBitmap;

        /* internal */ /* var */_list: List;

        /* internal */ /* var */_delayTimer: Object /* flash.utils.Timer */;

        /* internal */ /* var */_dataProvider: DataProvider;

        /* internal */ /* var */_target: Object /* flash.display.DisplayObject */;
    }
